#region Referencias
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Collections.Generic;
using System.Collections;
#endregion

/// <summary>
/// Summary description for DataOutoutStream
/// </summary>
namespace J2ME.RMS
{
    public class DataOutputStream
    {
        public List<byte> arrInt;

        private Int16 li = 0;

        public byte[] getArray()
        {
            byte[] byteEnvio = new byte[arrInt.Count];

            for (int i = 0; i < arrInt.Count; i++)
            {
                byteEnvio[i] = arrInt[i];
            }
            return byteEnvio;
        }

        public DataOutputStream()
        {
            arrInt = new List<byte>();
        }

        public void writeInt(int v)
        {
            arrInt.Add((byte)((v >> 24) & 0xFF));
            arrInt.Add((byte)((v >> 16) & 0xFF));
            arrInt.Add((byte)((v >> 8) & 0xFF));
            arrInt.Add((byte)((v >> 0) & 0xFF));

        }


        public void writeString(String s)
        {
            li = 1;

            char[] arrChar = s.ToCharArray();

            writeInt(arrChar.Length);

            for (int i = 0; i < arrChar.Length; i++)
            {
                char v = arrChar[i];
                writeChar(v);
            }
        }


        public void writeChar(char v)
        {

            arrInt.Add((byte)((v >> 8) & 0xFF));
            arrInt.Add((byte)((v >> 0) & 0xFF));

        }
     
        public void writeByte(byte v) {
	  
	        arrInt.Add(v);
        }

        public void write(byte[] b)
        {
            for (int i = 0; i < b.Length; i++)
            {
                arrInt.Add(b[i]);
            }
        }

        public void writeShort(short v)
        {
            arrInt.Add((byte)((v >> 8) & 0xFF));
            arrInt.Add((byte)((v >> 0) & 0xFF));

        }

        public void writeLong(long v)
        {

            arrInt.Add((byte)((v >> 56) & 0xFF));
            arrInt.Add((byte)((v >> 48) & 0xFF));
            arrInt.Add((byte)((v >> 40) & 0xFF));
            arrInt.Add((byte)((v >> 32) & 0xFF));
            arrInt.Add((byte)((v >> 24) & 0xFF));
            arrInt.Add((byte)((v >> 16) & 0xFF));
            arrInt.Add((byte)((v >> 8) & 0xFF));
            arrInt.Add((byte)((v >> 0) & 0xFF));

        }

        public void clear()
        {
            if (arrInt != null)
            {
                arrInt.Clear();
                arrInt = null;
            }
        }
    }
}